<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 68KB
 *
 * An open source knowledge base script
 *
 * @package		68kb
 * @author		68kb Dev Team
 * @copyright	Copyright (c) 2009, 68 Designs, LLC
 * @license		http://68kb.com/user_guide/license.html
 * @link		http://68kb.com
 * @since		Version 1.0
 */

// ------------------------------------------------------------------------

/**
 * Category Model
 *
 * This class is used to handle the categories data.
 *
 * @package		68kb
 * @subpackage	Models
 * @category	Models
 * @author		68kb Dev Team
 * @link		http://68kb.com/user_guide/overview/download_link.html
 * @version 	$Id: download_link_model.php 89 2009-08-13 01:54:20Z suzkaw68 $
 */
class Download_Link_model extends CI_model
{	
	/**
	 * Constructor
	 *
	 * @uses 	get_settings
	 * @return 	void
	 */
	function __construct()
	{
		parent::__construct();
		$this->load->database();
		log_message('debug', 'download link Model Initialized');
	}
	
	// ------------------------------------------------------------------------
	
	/**
	* Format URI
	* 
	* Formats a category uri.
	* 
	* @param	string $cat_uri The uri name
	* @uses 	check_uri
	* @uses		remove_accents
	* @uses		seems_utf8
	* @uses		utf8_uri_encode
	* @uses		format_uri
	* @return	string A cleaned uri
	*/
	function format_uri($cat_uri, $i=0, $cat_id=false)
	{
		$cat_uri = strip_tags($cat_uri);
		// Preserve escaped octets.
		$cat_uri = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $cat_uri);
		// Remove percent signs that are not part of an octet.
		$cat_uri = str_replace('%', '', $cat_uri);
		// Restore octets.
		$cat_uri = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $cat_uri);
		
		$cat_uri = remove_accents($cat_uri);
		if (seems_utf8($cat_uri)) 
		{
			if (function_exists('mb_strtolower')) 
			{
				$cat_uri = mb_strtolower($cat_uri, 'UTF-8');
			}
			$cat_uri = utf8_uri_encode($cat_uri, 200);
		}

		$cat_uri = strtolower($cat_uri);
		$cat_uri = preg_replace('/&.+?;/', '', $cat_uri); // kill entities
		$cat_uri = preg_replace('/[^%a-z0-9 _-]/', '', $cat_uri);
		$cat_uri = preg_replace('/\s+/', '-', $cat_uri);
		$cat_uri = preg_replace('|-+|', '-', $cat_uri);
		$cat_uri = trim($cat_uri, '-');
		
		if ($i>0) 
		{
			$cat_uri=$cat_uri."-".$i;
		}
		
		if (!$this->check_uri($cat_uri, $cat_id)) 
		{
			$i++;
			$cat_uri=$this->format_uri($cat_uri, $i);
		}
		return $cat_uri;
	}
		
	// ------------------------------------------------------------------------
	
	/**
	 * Get Category By ID.
	 *
	 * Get a single category from its id
	 *
	 * @access	public
	 * @param	int	the unique id
	 * @return	array
	 */
	function getLinkDownloadByBookId($book_id)
	{
		$book_id=(int)$book_id;
		$this->db->from('links')->where('cat_id', $book_id);
		$query = $this->db->get();
		$data = $query->row();
		$query->free_result();
		return  $data;
	}
	
}
	
/* End of file category_model.php */
/* Location: ./upload/includes/application/models/category_model.php */ 
